package cn.com.connected.service.impl;

import cn.com.connected.base.cache.CacheService;
import cn.com.connected.base.utils.StringTools;
import cn.com.connected.service.LoginService;
import cn.com.connected.service.MemberService;
import cn.com.connected.service.SmsService;
import cn.com.connected.service.TokenService;
import cn.com.connected.vo.base.LoginVo;
import cn.com.connected.vo.base.TokenVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static cn.com.connected.common.emnus.CacheKey.LOGIN_TOKEN;

/**
 * @program: sameway-server
 * @description: 登陆
 * @author: 邵明生
 * @create: 2019-03-12 15:32
 **/
@Service
@Slf4j
public class LoginServiceImpl implements LoginService {
    @Resource
    private MemberService memberService;

    @Resource
    private TokenService tokenService;

    @Resource
    private SmsService smsService;

    @Resource
    private CacheService cacheService;

    @Override
    public LoginVo createToken(String memberId) {
        TokenVO tokenVO = TokenVO.builder()
                .id(memberId)
                .scope("school")
                .build();
        String token = tokenService.createToken(tokenVO);
        cacheService.putObject(StringTools.format(LOGIN_TOKEN,memberId),token);
        return LoginVo.builder().token(token).build();
    }


}
